#ifndef MYHEAP_H
#define MYHEAP_H

#include <QtCore>

#include "myarray.h"

namespace sk {

void heapsort(int* arr, int length);

class MyHeap {
public:
    virtual int getMin() = 0;
    virtual int extractMin() = 0;
    virtual void insert(int value) = 0;
    virtual void buildHeap(const MyArray& arr) = 0;
    virtual int size() = 0;
    virtual void print() = 0;
};

class MyHeapImp : public MyHeap {
private:
    MyArray arr;
    int length;

    void heapifyUp(int index);
    void heapifyDown(int index);
    int parent(int index);
    int left(int index);
    int right(int index);

public:
    friend void heapsort(int* arr, int length);

    MyHeapImp();

    int getMin();
    int extractMin();
    void insert(int value);
    void buildHeap(const MyArray& arr);
    int size();
    void print();
};

}

#endif // MYHEAP_H
